package com.junchao.peng.controller;

import com.junchao.peng.service.FileService;
import com.junchao.peng.utils.JsonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author dell
 */
@RestController
@RequestMapping("/file")
public class FileController {
    @Resource
    FileService fileService;

    @ApiOperation("数据库中所有文件")
    @GetMapping("/listFile")
    public JsonResult listFile(String token){
     return fileService.listFile(token);
    }

    @ApiOperation("根据id查询文件")
    @GetMapping("/selectByPrimaryKey")
    public JsonResult selectByPrimaryKey(Integer id, String token){
        return fileService.selectByPrimaryKey(id,token);
    }

    @ApiOperation("根据url查询文件")
    @GetMapping("/selectByUrl")
    public JsonResult selectByUrl(String url, String token){
        return fileService.selectByUrl(url,token);
    }

    @ApiOperation("上传文件")
    @PostMapping("/insertSelective")
    public JsonResult insertSelective(MultipartFile file, String token){
        return fileService.insertSelective(file,token);
    }

    @ApiOperation("删除文件")
    @DeleteMapping("/deleteByPrimaryKey")
    public JsonResult deleteByPrimaryKey(Integer id, String token){
        return fileService.deleteByPrimaryKey(id,token);
    }
}
